package com.unit5;

import java.io.*;

/**
 * @author 李琦 on 2021/8/12.
 * @version java version "16.0.1" 2021-04-20
 * 缓冲字符输出输入流BufferedReader
 */
public class test6 {
    public static void main(String[] args) {
        File file=new File("E:\\padata\\李琦.txt");
        BufferedReader br=null;
        BufferedWriter bw=null;
        try {
            br=new BufferedReader(new FileReader(file));
            bw=new BufferedWriter(new FileWriter("E:\\padata\\我有一个恋爱.txt"));
            String str=br.readLine();//逐行读取字符串
            while(str!=null){
                System.out.println(str);
                bw.write(str+"\n");//写入,顺便换行
                bw.flush();//清空缓冲区数据,并强制写入磁盘
                str=br.readLine();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                br.close();
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }




}
